#include "UdpServer.hpp"

int main(int argc, char* argv[])
{
  if (argc != 2)
  {
    std::cerr << "./udpserver port" << "\n";
    return 1;
  }
  UdpServer* server = new UdpServer(atoi(argv[1]));  // 创建udpserver对象
  string buffer;
  while (true)
  {
    // udp服务器不断接收信息，对信息进行处理
    ClientInfo clientInfo; 
    clientInfo = server->RecvMessage(buffer);  // 接收消息 -阻塞
    if (clientInfo.isRecv)
    {
      // 接收成功
      std::cout << clientInfo.ip << ": " << clientInfo.port << "sendto [" << buffer << "]\n";
      // 服务器服务，返回相同的
      server->SendMessage(clientInfo.ip, clientInfo.port, buffer);
    }
  }
  return 0;
}
